/*
 * XMLAttribute.cpp
 *
 *  Created on: 2010-3-25
 *      Author: wenjian
 */

#include <string.h>
#include <vector>
#include "XMLAttribute.h"

using namespace std;

namespace Try {
  XMLAttribute::XMLAttribute(const char* n, const char* v)
    :name(NULL), value(NULL){
    setName(n);
    setValue(v);
  }
  XMLAttribute::~XMLAttribute(){
    if(name!=NULL)delete[] name;
    if(value!=NULL)delete[] value;
  }

  /**
   * 返回属性名
   */
  const char* XMLAttribute::getName()const{
    return name;
  }

  /**
   * 设置属性名
   */
  XMLAttribute* XMLAttribute::setName(const char* name){
    if(name!=NULL){
      unsigned int len = strlen(name);
      if(this->name==NULL){
        this->name = new char[len+1];
      }else if(strlen(this->name)<len){
        char* tmp = this->name;
        this->name = new char[len+1];
        delete[] tmp;
      }
      strcpy(this->name, name);
    }
    return this;
  }

  /**
   * 返回属性值
   */
  const char* XMLAttribute::getValue()const{
    return value;
  }

  /**
   * 设置属性值
   */
  XMLAttribute* XMLAttribute::setValue(const char* value){
    if(value!=NULL){
      unsigned int len = strlen(value);
      if(this->value==NULL){
        this->value = new char[len+1];
      }else if(strlen(this->value)<len){
        char* tmp = this->value;
        this->value = new char[len+1];
        delete[] tmp;
      }
      strcpy(this->value, value);
    }
    return this;
  }

}
